package com.qianyanglong.m3u88.download.app.frame;

import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.resource.ResourceUtil;
import com.qianyanglong.m3u88.download.app.table.HomeTable;
import com.qianyanglong.m3u88.download.app.table.editor.HomeCellEditor;
import com.qianyanglong.m3u88.download.app.table.model.HomeTableModel;
import com.qianyanglong.m3u88.download.app.table.render.HomeCellRender;
import com.qianyanglong.m3u88.download.app.table.vo.HomeTableVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class HomeFrame extends JFrame {

    private static final Logger logger = LoggerFactory.getLogger(HomeTableModel.class);

    public HomeFrame(){
        //https://www.x9g2q.com/index/home.html
        //https://mzjvl.com/
        //https://hacg.foo/wp/category/all/anime/
        this.setTitle("毛片下载器");
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setExtendedState(MAXIMIZED_BOTH);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        try {
            BufferedImage read = ImageIO.read(ResourceUtil   .getResource("ss.png").openStream());
            this.setIconImage(read);
        } catch (IORuntimeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //获取宽度
        int width = getWidth();
        //获取高度
        int height = getHeight();
        List<HomeTableVO> list = new ArrayList<>();
        HomeTableVO homeTableVO = new HomeTableVO();
        homeTableVO.setId(1);
        homeTableVO.setName("测试");
        homeTableVO.setAddress("https://www.baidu.com");
        homeTableVO.setProgress("98%");
        homeTableVO.setOperation("试试");
        list.add(homeTableVO);
        HomeTable homeTable = new HomeTable(new HomeTableModel(list));
        homeTable.getColumnModel().getColumn(4).setCellRenderer(new HomeCellRender());
        homeTable.getColumnModel().getColumn(4).setCellEditor(new HomeCellEditor());
        JScrollPane tablePanel = new JScrollPane(homeTable);
        tablePanel.setBounds((int)(width*0.008),(int)(height*0.01),(int)(width*0.98),(int)(height*0.98));
        this.add(tablePanel);
        logger.info("位置：{}，{}，{}，{}",(int)(width*0.05),(int)(height*0.05),(int)(width*0.9),(int)(height*0.9));
        this.repaint();
        System.out.println("测试");
    }

}
